package com.lucy.nepu.module.htopic.rule;

import cn.hutool.core.lang.Validator;
import com.lucy.nepu.module.htopic.constant.HorTopicTypeConst;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IsHorTopicTypeValidator implements ConstraintValidator<IsHorTopicType, Object> {

    @Override
    public void initialize(IsHorTopicType constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        if (Validator.isEmpty(o)){
            return false;
        }
        String type = o.toString();
        if (type.equals(HorTopicTypeConst.NATURAL) || type.equals(HorTopicTypeConst.SOCIAL)){
            return true;
        }
        return false;
    }
}
